﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using DataLayer.Controller;

public partial class StateAccount : cGlobal
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {            
            //grvFactura.DataSource = ClientController.GetPSECredito("444444444-00"); ;
            //grvFactura.DataBind();

            if(Request.Params["NIT"] != null)
            {
                grvFactura.DataSource = ClientController.GetPSECredito(Request.Params["NIT"]); ;
                grvFactura.DataBind();
            }
        }
    }   

    protected void grvFactura_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            HyperLink hplFactura = (HyperLink)e.Row.FindControl("hplFactura");
            hplFactura.NavigateUrl = ConfigurationManager.AppSettings["urlFactura"].ToString() + DataBinder.Eval(e.Row.DataItem, "NUMERO_FACTURA").ToString().Trim() + "_" + DateTime.Parse(DataBinder.Eval(e.Row.DataItem, "FECHA_FACTURA").ToString()).ToString("ddMMyyyy") + ".pdf";

            
            
            HyperLink hplSupport = (HyperLink)e.Row.FindControl("hplSupport");
            Label lblDoc = (Label)e.Row.FindControl("lblDoc");

            /*int countDoc = int.Parse(DataBinder.Eval(e.Row.DataItem, "COUNT_DOC").ToString());
            lblDoc.Text = countDoc.ToString();
            if (countDoc > 0)*/

            hplSupport.NavigateUrl = "Javascript:openShadowbox('" + ConfigurationManager.AppSettings["urlPortal"] + "/client/DocSupport.aspx?NoFactura=" + DataBinder.Eval(e.Row.DataItem, "NUMERO_FACTURA").ToString().Trim() + "','iframe','Documentos de Soporte',590,400);";            

           
            HyperLink hplPay = (HyperLink)e.Row.FindControl("hplPay");
            hplPay.NavigateUrl = "Javascript:openShadowbox('" + ConfigurationManager.AppSettings["urlPortal"] + "/client/Payment.aspx?NoFactura=" + DataBinder.Eval(e.Row.DataItem, "NUMERO_FACTURA").ToString().Trim() + "&Nit=" + Request.Params["NIT"].ToString() + "&Valor=" + DataBinder.Eval(e.Row.DataItem, "VALOR_TOTAL_FACTURA") + "&usrNombre=" + Request.Params["usrNombre"].ToString() + "&Subtotal=" + DataBinder.Eval(e.Row.DataItem, "SUBTOTAL_FACTURA") + "&Iva=" + DataBinder.Eval(e.Row.DataItem, "IVA_FACTURA") + "','iframe','Pagos Online',395,375);";
            //hplPay.NavigateUrl = "Javascript:openShadowbox('" + ConfigurationManager.AppSettings["urlPortal"] + "/client/Payment.aspx?NoFactura=" + DataBinder.Eval(e.Row.DataItem, "NUMERO_FACTURA").ToString().Trim() + "&Nit=444444444-00&Valor=" + DataBinder.Eval(e.Row.DataItem, "VALOR_TOTAL_FACTURA") + "&usrNombre=NombreDelUsuario&Subtotal=" + DataBinder.Eval(e.Row.DataItem, "SUBTOTAL_FACTURA") + "&Iva=" + DataBinder.Eval(e.Row.DataItem, "IVA_FACTURA") + "','iframe','Pagos Online',395,375);";            
        }
    }
  
    protected void btnHistory_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect(ConfigurationManager.AppSettings["urlPortal"] + "client/HistoryPayment.aspx?NIT=" + Request.Params["NIT"].ToString() + "&usrNombre=" + Request.Params["usrNombre"].ToString());
    }
}